﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.SessionState;

namespace YeaTrip.Framework.CookieSession
{
    /// <summary>
    /// Session类型枚举
    /// </summary>
    public enum SessionEnum
    {
        LoginAccount = 0,
        LoginValidateCode,  //验证码
        CustName
    }

    /// <summary>
    /// Session操作类
    /// </summary>
    public class YeaTripSession
    {
        private HttpSessionStateBase httpSessionStateBase;
        private HttpSessionState httpSessionState;

        public YeaTripSession(HttpSessionStateBase session)
        {
            httpSessionStateBase = session;
            httpSessionState = null;
        }

        public YeaTripSession(HttpSessionState session)
        {
            httpSessionState = session;
            httpSessionStateBase = null;
        }

        /// <summary>
        /// 设置Session值
        /// </summary>
        /// <param name="session">指定的Session</param>
        /// <param name="value">值</param>
        public void SetSession(SessionEnum session, object value)
        {
            string sessionName = session.ToString();
            if (httpSessionStateBase != null)
            {
                httpSessionStateBase[sessionName] = value;
            }
            else
            {
                httpSessionState[sessionName] = value;
            }
        }

        /// <summary>
        /// 获取Session值
        /// </summary>
        /// <param name="session">指定的Session</param>
        /// <returns></returns>
        public object GetSession(SessionEnum session)
        {
            string sessionName = session.ToString();
            if (httpSessionStateBase != null)
            {
                return httpSessionStateBase[sessionName];
            }
            else
            {
                return httpSessionState[sessionName];
            }
        }
    }
}
